﻿#region Copyright
// Partial Copyright (c) LogoUI Software Solutions LTD
// Author: Vladislav Spivak
// This source file is the part of LogoFX Framework http://logofx.codeplex.com
// See accompanying licences and credits.
#endregion


using System;
using System.Collections.Generic;
using System.Windows;
#if !WinRT
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Interactivity;
using LogoFX.Core;
using EventTrigger = System.Windows.Interactivity.EventTrigger;
#else
using LogoFX.Core;
using Windows.UI.Interactivity;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using EventTrigger = Windows.UI.Interactivity.EventTrigger;
#endif

namespace LogoFX.Infra.Interactivity
{
    /// <summary>
    /// Provides <see cref="FrameworkElement"/> with random background
    /// </summary>
    public class BackgroundBrushBehavior : Behavior<FrameworkElement>
    {
        #region Fields

        private static readonly Random s_rnd = new Random();

        #endregion

        #region Constructors

        public BackgroundBrushBehavior()
        {
            Brushes = new List<Brush>();
        }

        #endregion

        #region Dependency Properties

        #endregion

        #region Public Properties

        public List<Brush> Brushes { get; private set; }

        #endregion

        #region Overrides

        protected override void OnAttached()
        {
            Brush brush = Brushes[s_rnd.Next(Brushes.Count)];

            if (AssociatedObject is Control)
            {
                ((Control) AssociatedObject).Background = brush;
            }
            else if (AssociatedObject is Panel)
            {
                ((Panel)AssociatedObject).Background = brush;
            }
        }

        #endregion
    }
}
